import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "概况总览",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },
  // 用户管理
  {
    path: "/user",
    component: Layout,
    meta: { title: "用户管理", icon: "user" },
    children: [
      {
        name: "UserAdmin",
        path: "/userAdmin",
        component: () => import("@/views/userAdmin/admin.vue"),
        meta: { title: "用户管理" },
      },
      {
        name: "UserAdminTrain",
        path: "/userAdminTrain",
        component: () => import("@/views/userAdmin/train.vue"),
        meta: { title: "任务记录" },
      },
      {
        name: "learningList",
        path: "/LearningList",
        component: () => import("@/views/userAdmin/learningList.vue"),
        meta: { title: "课程列表" },
      }
    ],
  },
  // 课程管理
  {
    path: "/curriculum",
    component: Layout,
    meta: { title: "课程管理", icon: "curriculum" },
    children: [
      {
        name: "CurriculumClass",
        path: "/curriculumClass",
        component: () => import("@/views/curriculum/class.vue"),
        meta: { title: "课程分类" },
      },
      {
        name: "VideoAdmin",
        path: "/videoAdmin",
        redirect: '/curriculum/videoAdmin/video',
        component: () => import("@/views/curriculum/videoAdmin/video.vue"),
        meta: { title: "专题管理" },
        children: [
          {
            name: "Video",
            path: "/video",
            component: () => import("@/views/curriculum/videoAdmin/video.vue"),
            meta: { title: "视频专题" },
          }
        ]
      },
      {
        name: "Material",
        path: "/material",
        redirect: '/curriculum/material/type',
        component: () => import("@/views/curriculum/material/index.vue"),
        meta: { title: "素材管理" },
        children: [
          {
            name: "MaterialType",
            path: "/materialType",
            component: () => import("@/views/curriculum/material/type.vue"),
            meta: { title: "素材分类" },
          },
          {
            name: "MaterialList",
            path: "/materialList",
            component: () => import("@/views/curriculum/material/list.vue"),
            meta: { title: "素材列表" },
          }
        ]
      }
    ],
  },
  // 证书管理
  // {
  //   path: "/certificate",
  //   component: Layout,
  //   meta: { title: "证书管理", icon: "certificate" },
  //   children: [
  //     {
  //       name: "CertificateList",
  //       path: "/certificateList",
  //       component: () => import("@/views/certificate/list.vue"),
  //       meta: { title: "证书列表" },
  //     },
  //     {
  //       name: "Certificaterecord",
  //       path: "/certificaterecord",
  //       component: () => import("@/views/certificate/record.vue"),
  //       meta: { title: "证书记录" },
  //     }
  //   ],
  // },
  // 问卷管理
  {
    path: "/exam",
    component: Layout,
    meta: { title: "考试管理", icon: "exam" },
    children: [
      {
        name: "ExamAdmin",
        path: "/examAdmin",
        redirect: '/exam/examAdmin/type',
        component: () => import("@/views/exam/examAdmin/index.vue"),
        meta: { title: "题库管理" },
        children: [
          {
            name: "ExamAdminType",
            path: "/examAdminType",
            component: () => import("@/views/exam/examAdmin/type.vue"),
            meta: { title: "题库分类" },
          },
          {
            name: "ExamAdminList",
            path: "/examAdminList",
            component: () => import("@/views/exam/examAdmin/list.vue"),
            meta: { title: "题库列表" },
          }
        ]
      },
      {
        name: "TopicAdmin",
        path: "/topicAdmin",
        redirect: '/exam/topicAdmin/type',
        component: () => import("@/views/exam/topicAdmin/index.vue"),
        meta: { title: "考试管理" },
        children: [
          {
            name: "TopicAdminType",
            path: "/topicAdminType",
            component: () => import("@/views/exam/topicAdmin/type.vue"),
            meta: { title: "考试分类" },
          },
          {
            name: "TopicAdminList",
            path: "/topicAdminList",
            component: () => import("@/views/exam/topicAdmin/list.vue"),
            meta: { title: "考试列表" },
          },
          {
            name: "TopicAdminLog",
            path: "/topicAdminLog",
            component: () => import("@/views/exam/topicAdmin/log.vue"),
            meta: { title: "考试记录" },
          }
        ]
      }
    ],
  },
  // 证书管理
  {
    path: "/task",
    component: Layout,
    meta: { title: "任务管理", icon: "task" },
    redirect: '/views/task/list',
    children: [
      {
        name: "TaskList",
        path: "/taskList",
        component: () => import("@/views/task/list.vue"),
        meta: { title: "任务列表", icon: "task" },
      }
    ],
  },
  // 证书管理
  // {
  //   path: "/setUp",
  //   component: Layout,
  //   meta: { title: "系统设置", icon: "task" },
  //   redirect: '/views/setUp/index',
  //   children: [
  //     {
  //       name: "System",
  //       path: "/system",
  //       redirect: '/views/setUp/system/alyset',
  //       component: () => import("@/views/setUp/index.vue"),
  //       meta: { title: "系统设置" },
  //       children: [
  //         {
  //           name: "SystemAlyset",
  //           path: "/systemAlyset",
  //           component: () => import("@/views/setUp/system/alyset.vue"),
  //           meta: { title: "阿里云设置" },
  //         }
  //       ]
  //     },
  //     {
  //       name: "auth",
  //       path: "/auth",
  //       redirect: '@/views/setUp/system/auth',
  //       component: () => import("@/views/setUp/index.vue"),
  //       meta: { title: "权限管理", },
  //       children: [
  //         {
  //           name: "AuthIdentity",
  //           path: "/authIdentity",
  //           component: () => import("@/views/setUp/auth/identity.vue"),
  //           meta: { title: "身份管理" },
  //         },
  //         {
  //           name: "AuthAdminList",
  //           path: "/authAdminList",
  //           component: () => import("@/views/setUp/auth/adminList.vue"),
  //           meta: { title: "管理员管理" },
  //         },
  //         {
  //           name: "AuthAuth",
  //           path: "/authAuth",
  //           component: () => import("@/views/setUp/auth/auth.vue"),
  //           meta: { title: "权限规则" },
  //         }
  //       ]
  //     },
  //     {
  //       name: "TaskList",
  //       path: "/taskList",
  //       component: () => import("@/views/task/list.vue"),
  //       meta: { title: "短信设置" },
  //       children: [
  //         {
  //           name: "AuthIdentity",
  //           path: "/authIdentity",
  //           component: () => import("@/views/setUp/auth/identity.vue"),
  //           meta: { title: "短息模版" },
  //         },
  //         {
  //           name: "AuthAdminList",
  //           path: "/authAdminList",
  //           component: () => import("@/views/setUp/auth/adminList.vue"),
  //           meta: { title: "短信服务" },
  //         },
  //         {
  //           name: "AuthAuth",
  //           path: "/authAuth",
  //           component: () => import("@/views/setUp/auth/auth.vue"),
  //           meta: { title: "短信账号" },
  //         }
  //       ]
  //     },
  //     {
  //       name: "TaskList",
  //       path: "/taskList",
  //       component: () => import("@/views/task/list.vue"),
  //       meta: { title: "阿里云设置", icon: "task" },
  //     }
  //   ],
  // },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/" });
}

export default router;
